package com.cmcc.aregister.ui.adapter;

import java.util.List;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;
import com.cmcc.aregister.R;
import com.cmcc.aregister.cs.asntask.InterfaceUtils.DataCallback_other;
import com.cmcc.aregister.cs.lazyimage.LazyImageView;
import com.cmcc.aregister.cs.model.AreaModel;
import com.cmcc.aregister.cs.model.DepModel;
import com.cmcc.aregister.cs.model.DocModel;

public class ChoiceOtherDocAdapter extends BaseAdapter {
	private Context context = null;
	public List<DocModel> list = null;
	public boolean isEnd = true;
	DataCallback_other inc;

	public ChoiceOtherDocAdapter(Context context, List<DocModel> list,boolean isEnd,DataCallback_other inc) {
		this.context = context;
		this.list = list;
		this.isEnd = isEnd;
		this.inc = inc;
	}

	public int getCount() {
		int size = list.size();
		if (!isEnd) {
			return size + 1;
		} else {
			return size;
		}
	}

	public Object getItem(int position) {
		return position;
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		if (position >= list.size()) {
			convertView = LayoutInflater.from(context).inflate(
					R.layout.list_wait, null);
			convertView.setTag(null);
			convertView.setEnabled(false);
			inc.next_updateData_Doc();
			return convertView;
		} else {
			ViewHolder holder;
			if (convertView != null && convertView.getTag() != null) {
				holder = (ViewHolder) convertView.getTag();
			} else {
				holder = new ViewHolder();
				convertView = LayoutInflater.from(context).inflate(
						R.layout.a_choice_other_doc, null);
				holder.image = (LazyImageView) convertView
						.findViewById(R.id.image);
				holder.name = (TextView) convertView.findViewById(R.id.name);
				holder.title = (TextView) convertView.findViewById(R.id.title);
				holder.outType = (TextView) convertView.findViewById(R.id.outType);
				holder.detail = (Button) convertView.findViewById(R.id.detail);
				holder.detail.setOnClickListener(onClickListener);
				convertView.setTag(holder);
			}
			holder.detail.setTag(position);
			holder.name.setText(list.get(position).doctorname);
			holder.title.setText(list.get(position).title);
			holder.outType.setText(list.get(position).outType);
			holder.image.loadImage(list.get(position).photoUrl, 0, 1);
			return convertView;
		}
	}
	
	OnClickListener onClickListener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			inc.callback_doc_info((Integer) v.getTag());
		}
	};
	
	static class ViewHolder {
		LazyImageView image;
		TextView name;
		TextView title;
		TextView outType;
		Button detail;
	}
}